﻿using System;
using JTLeigh.Commerce.Spencer.Core.Common;

namespace JTLeigh.Commerce.Spencer.Features.ProductImages.Common.Entities
{

	/// <summary>
	/// Wraps a product image view and an optional localization, and exposes properties from these 
	/// objects with fallback when the objects are <see langword="null"/>.
	/// </summary>
	public class LocalizedProductImageView
	{

		#region Fields

		private ProductImageView _view;
		private ProductImageViewLocalization _localization;

		#endregion // Fields

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="LocalizedProductImageView"/> class with 
		/// the specified view and localization.
		/// </summary>
		/// <param name="view">The <see cref="ProductImageView"/> to wrap.</param>
		/// <param name="localization">The <see cref="ProductImageViewLocalization"/> to wrap, or
		/// <see langword="null"/> if no localization was found.</param>
		public LocalizedProductImageView(ProductImageView view, ProductImageViewLocalization localization)
		{
			Safety.AssertArgumentNotNull("view", view);
			// localization can be null

			_view = view;
			_localization = localization;
		}

		#endregion // Constructors

		#region Properties

		/// <summary>
		/// Gets the view identifier.
		/// </summary>
		/// <value>A view identifier <see cref="Guid"/>.</value>
		public Guid ViewId
		{
			get { return _view.ViewId; }
		}

		/// <summary>
		/// Gets the well-known view code.
		/// </summary>
		/// <value>A well-known view code <see cref="Byte"/>.</value>
		public byte WellKnownViewCode
		{
			get { return _view.WellKnownViewCode; }
		}

		/// <summary>
		/// Gets the order in which the view should be displayed.
		/// </summary>
		/// <value>An <see cref="Int32"/> ordinal position.</value>
		public int DisplayOrder
		{
			get { return _view.DisplayOrder; }
		}

		/// <summary>
		/// Gets the name of the view.
		/// </summary>
		/// <value>If a localization was provided, the localization's name.  Otherwise, the view's
		/// default name.</value>
		public string Name
		{
			get { return (_localization != null) ? _localization.Name : _view.DefaultName; }
		}

		#endregion // Properties

	}

}
